<?php
/**
 * This file is part of Hyperf Mall.
 *
 * @link     https://gitee.com/scwlkj/hyperf_mall
 * @contact  hyperf_mall@163.com
 */

declare(strict_types=1);

namespace App\JsonRpc;

use App\Constants\CouponConstants;
use App\Repository\CouponReceiveRepository;
use Hyperf\RpcServer\Annotation\RpcService;
use App\JsonRpc\Interfaces\CouponReceiveServiceInterface;

/**
 * @RpcService(name="Activity::CouponReceiveService", protocol="jsonrpc", server="jsonrpc")
 */
class CouponReceiveService extends BaseService implements CouponReceiveServiceInterface
{
    public function init()
    {
        $this->repository = CouponReceiveRepository::getInstance();
    }

    /**
     * Notes: 会员领取的优惠券列表
     * Author: Bruce.z
     * DateTime: 2022/9/13 10:55
     * @param array $condition
     * @param int $page
     * @param int $size
     * @return array
     */
    public function memberCoupon(array $condition, int $page, int $size):array
    {
        return $this->repository->memberCoupon($condition, $page, $size);
    }

    /**
     * Notes: 会员可用优惠券数量
     * Author: Bruce.z
     * DateTime: 2022/9/13 14:43
     * @param int $member_id
     * @return int
     */
    public function memberCount(int $member_id):int
    {
        return $this->repository->getCount(['member_id'=>$member_id,'status'=>CouponConstants::COUPON_RECEIVE_UNUSEING]);
    }

    /**
     * Notes: A端 活动 发放列表
     * Author: Bruce.z
     * DateTime: 2022/9/15 14:09
     * @param int $coupon_id
     * @param int $page
     * @param int $size
     * @return array
     */
    public function getList(int $coupon_id, int $page, int $size):array
    {
        return $this->repository->getList($coupon_id, $page, $size);
    }
}
